# ai_processing/news_scorer.py
from datetime import datetime
from config import Config

def calculate_comprehensive_score(news):
    """计算综合新闻分数"""
    score = 0

    # 实体权重分
    if news.involved_brands:
        for brand in news.involved_brands:
            weight = Config.ENTITY_WEIGHTS.get(brand, Config.ENTITY_WEIGHTS.get('default', 1))
            score += weight

    # 时效性分
    if news.publish_date:
        hours_old = (datetime.utcnow() - news.publish_date).total_seconds() / 3600
        time_base_score = getattr(Config, 'TIME_BASE_SCORE', 24)
        time_score = time_base_score / (hours_old + 1)
        score += time_score

    return round(score, 2)
